package cn.csq.sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @author csq
 * @version 1.0.0
 * @ClassName Main.java
 * @Description TODO
 * @createTime 2022年02月13日 20:07:00
 */
public class Main {

    public static void main(String[] args) {
        ArrayList<Apple> inventory = new ArrayList<>();
        Apple apple1 = new Apple();
        apple1.setWeight(10);
        Apple apple2 = new Apple();
        apple2.setWeight(2);
        inventory.add(apple1);
        inventory.add(apple2);

        Collections.sort(inventory, new Comparator<Apple>(){
            @Override
            public int compare(Apple o1, Apple o2) {
                return o1.getWeight().compareTo(o2.getWeight());
            }
        });
        System.out.println(inventory);


        inventory.sort(Comparator.comparing(Apple::getWeight));
    }

}
